//
//  ZSuccessfulAgainView.m
//  DoctorFAQs
//
//  Created by zjq on 17/3/9.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "ZSuccessfulAgainView.h"
@interface ZSuccessfulAgainView ()<UIGestureRecognizerDelegate> {
    UIView * _witheView;
    UILabel * _contextLabel;
    UIButton * _fixBtn;
}

@end

@implementation ZSuccessfulAgainView
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initlizeInterface];
    }
    return self;
}

- (void)initlizeInterface {
    self.backgroundColor = [UIColor colorWithRed:28/255.0 green:28/255.0 blue:28/255.0 alpha:0.4];// 将背景设置为半透明
    [self makeSubView];
    [self addAllSubView];
    [self makeAllSubViewMasnoy];
    [self addTheTap];

}

- (void)makeSubView {
    _witheView = [[UIView alloc] init];
    _witheView.backgroundColor = [UIColor whiteColor];
    
    _contextLabel = [[UILabel alloc] init];
    _contextLabel.font = [UIFont systemFontOfSize:15];
    _contextLabel.text = @"再次咨询成功，请耐心等待医生回复。";
    _contextLabel.numberOfLines = 2;
    
    _fixBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_fixBtn setTitle:@"确定" forState:UIControlStateNormal];
    [_fixBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _fixBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [_fixBtn addTarget:self action:@selector(fixBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)addAllSubView{
    [self addSubview:_witheView];
    [self addSubview:_contextLabel];
    [self addSubview:_fixBtn];
}

- (void)makeAllSubViewMasnoy {
    [_witheView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.8);
        make.height.offset(150*ysIZE);
    }];
    [_contextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_witheView).offset(10*xsIZE);
        make.right.equalTo(_witheView).offset(-10*xsIZE);
        make.top.equalTo(_witheView).offset(15*ysIZE);
        make.height.offset(50*ysIZE);
    }];
    [_fixBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_witheView).offset(-5*ysIZE);
        make.height.offset(25*ysIZE);
        make.width.offset(40*xsIZE);
        make.right.equalTo(_witheView).offset(-10*xsIZE);
        
    }];
}
- (void)addTheTap {
    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(event:)];
    tapGesture.delegate = self;
    [self addGestureRecognizer:tapGesture];
}
// 点击按钮
- (void)fixBtnAction:(UIButton *)sender {
    [self removeFromSuperview];
}

// 点击灰色部分
- (void)event:(UITapGestureRecognizer *)gesture {
    [self removeFromSuperview];
}
// 点击协议
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isDescendantOfView:_witheView] || [touch.view isDescendantOfView:_contextLabel] || [touch.view isDescendantOfView:_fixBtn]) {
        // 让其余控件 不响应此事件
        return NO;
    }
    return YES;
}

@end
